#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

struct Student {
    char name[105];
    int  score[4];
};
Student stu[105];

// 语文
bool cmp1(Student a, Student b) {
    if(a.score[0] != b.score[0]) {
        return a.score[0] > b.score[0];
    }

    return strcmp(a.name, b.name) < 0;
}

// 数学
bool cmp2(Student a, Student b) {
    if(a.score[1] != b.score[1]) {
        return a.score[1] > b.score[1];
    }

    return strcmp(a.name, b.name) < 0;
}

// 英语
bool cmp3(Student a, Student b) {
    if(a.score[2] != b.score[2]) {
        return a.score[2] > b.score[2];
    }

    return strcmp(a.name, b.name) < 0;
}

// 科学
bool cmp4(Student a, Student b) {
    if(a.score[3] != b.score[3]) {
        return a.score[3] > b.score[3];
    }

    return strcmp(a.name, b.name) < 0;
}

// 总分
bool cmp5(Student a, Student b) {
    int suma = 0, sumb = 0;
    for(int i = 0; i < 4; i++) {
        suma += a.score[i];
        sumb += b.score[i];
    }
    if(suma != sumb) {
        return suma > sumb;
    }

    return strcmp(a.name, b.name) < 0;
}

void print() {
    for(int i = 0; i < 3; i++) {
        printf("%s ", stu[i].name);
    }
    printf("%s\n", stu[3].name);
}

int main()
{
    int n;
    scanf("%d", &n);
    for(int i = 0; i < n; i++) {
        scanf("%s", stu[i].name);
        for(int j = 0; j < 4; j++) {
            scanf("%d", &stu[i].score[j]);
        }
    }
    sort(stu, stu+n, cmp1);
    print();
    sort(stu, stu+n, cmp2);
    print();
    sort(stu, stu+n, cmp3);
    print();
    sort(stu, stu+n, cmp4);
    print();
    sort(stu, stu+n, cmp5);
    print();

    return 0;
}
